package com.isoft.mapper;

import com.isoft.entity.DfoeDfdlEntity;
import org.apache.ibatis.annotations.*;

@Mapper
public interface DfoeDfdlMapper {

    @Insert("INSERT INTO MSG_META(SENDER, RECEIVER, SEQUENCE_NUMBER, DATE_TIME, MSG_TYPE, SUB_TYPE) VALUES(#{entity.meta.sender}, #{entity.meta.receiver}, #{entity.meta.sequenceNumber}, TO_TIMESTAMP(#{entity.meta.dateTime}, 'YYYYMMDDHH24MISS'), #{entity.meta.type}, #{entity.meta.subType})")
    @Options(useGeneratedKeys = true, keyProperty = "meta.msgId")
    void insertMeta(@Param("entity") DfoeDfdlEntity entity);

    @Insert("MERGE INTO FLIGHT_BASE USING (SELECT #{dflt.flightId} AS FLIGHT_ID, #{dflt.flightAttribute} AS FLIGHT_ATTRIBUTE, #{dflt.flightFileId} AS FLIGHT_FILE_ID, #{dflt.flightIdentifier} AS FLIGHT_IDENTIFIER FROM DUAL) S " +
            "ON (FLIGHT_BASE.FLIGHT_ID = S.FLIGHT_ID) " +
            "WHEN NOT MATCHED THEN INSERT (FLIGHT_ID, FLIGHT_ATTRIBUTE, FLIGHT_FILE_ID, FLIGHT_IDENTIFIER) " +
            "VALUES (#{dflt.flightId}, #{dflt.flightAttribute}, #{dflt.flightFileId}, #{dflt.flightIdentifier})")
    int insertFlightBase(DfoeDfdlEntity entity);
}